package cn.school.controller.teacher.evaluation;

import cn.school.common.api.CommonPage;
import cn.school.common.api.CommonResult;
import cn.school.common.utils.SysUserUtils;
import cn.school.sys.entity.SysUser;
import cn.school.teacher.evaluation.dto.TeacherEvaluationUserTaskDto;
import cn.school.teacher.evaluation.service.EvaluationUserTaskService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


@RestController
@Api(tags = "MyExeGradeTaskByTeacherEvaluation => 我的执行打分任务（参与某个老师的考评任务打分）")
@RequestMapping("teacher/evaluation/mytask/")
public class MyExeGradeTaskByTeacherEvaluation {
    @Autowired
    private EvaluationUserTaskService evaluationUserTaskService;

    @ApiOperation("/list => 我的打分任务列表")
    @PreAuthorize("@ss.hasPermi('teacher:evaluation:mytask:list')")
    @GetMapping("/list")
    public CommonResult<CommonPage<TeacherEvaluationUserTaskDto>> list(@RequestParam Map<String, Object> params) {
        SysUser loginUser = SysUserUtils.getSysUser();
        if (loginUser != null) {
            params.put("loginUserId", loginUser.getId().toString());
        }
        IPage<TeacherEvaluationUserTaskDto> page = this.evaluationUserTaskService.getPage(params);
        return CommonResult.success(CommonPage.restPage(page));
    }

    @ApiOperation("/list => 我的打分任务详情")
    @PreAuthorize("@ss.hasPermi('teacher:evaluation:mytask:list')")
    @GetMapping("/info/{teutId}")
    public CommonResult<TeacherEvaluationUserTaskDto> getInfo(@PathVariable(value = "teutId") String teutId) {
        Map<String, Object> params = new HashMap<>();
        SysUser loginUser = SysUserUtils.getSysUser();
        if (loginUser != null) {
            params.put("loginUserId", loginUser.getId());
        }
        params.put("teutId", teutId);
        TeacherEvaluationUserTaskDto teacherEvaluationUserTaskDto  = this.evaluationUserTaskService.getUserTaskItemData(params);
        return CommonResult.success(teacherEvaluationUserTaskDto);
    }

    @ApiOperation("/list => 我的打分任务详情")
    @PreAuthorize("@ss.hasPermi('teacher:evaluation:mytask:list')")
    @PostMapping("/saveOrSubmitData")
    public CommonResult<TeacherEvaluationUserTaskDto> saveOrSubmitData(@RequestBody TeacherEvaluationUserTaskDto teacherEvaluationUserTaskDto) {
        Map<String, Object> params = new HashMap<>();
        SysUser loginUser = SysUserUtils.getSysUser();
        if (loginUser != null) {
            params.put("loginUserId", loginUser.getId());
        }
        params.put("teacherEvaluationUserTaskDto", teacherEvaluationUserTaskDto);
        teacherEvaluationUserTaskDto  = this.evaluationUserTaskService.saveOrUpdateItemDate(params);
        return CommonResult.success(teacherEvaluationUserTaskDto);
    }



}
